import qs from 'qs';

// 删除同一个key下，有多个cookie值
export function enRemoveCookie(key) {
  // 没有指定的情况下，会删除当前完整域名下的 对应cookie，
  $nuxt.$cookiz.remove(key);
  // 需要指定 path 和 domain 否则无法删除
  $nuxt.$cookiz.remove(key, {
    domain: '.xxx.com',
    path: '/',
  });
}

export const navTo = (path) => {
  if (window?.location?.search) {
    const urlparams = qs.parse(window.location.search.substring(1));
    if (urlparams?.username) {
      if (path.includes('?')) {
        path = `${path}&username=${urlparams?.username}`;
      } else {
        path = `${path}?username=${urlparams?.username}`;
      }
    }
  }

  window.location.href = path;
};
